//
//  LSZDetailsVideoClassificationViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/11/14.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZDetailsVideoClassificationViewController.h"

@interface LSZDetailsVideoClassificationViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView * tableViewKnowledgeParty;
//@property(nonatomic,strong) NSMutableArray * mutArrayData;
@property(nonatomic,strong) NSMutableArray * mutArraySecondaryInterface;
@property(nonatomic,assign) NSInteger page;

@end

@implementation LSZDetailsVideoClassificationViewController

#pragma mark - 获得请求数据
-(void)getInformationDetails:(NSInteger)page
{
    __weak typeof(self) weakSelf = self;
    /*
    [LSZRequestDicData initWithDirectoryDetails:self.id_id page:page :^(BOOL isOK, NSString * str, LSZArticleDetailsManager * mg) {
        if (isOK == YES) {
            if(page == 0){
                [weakSelf.mutArraySecondaryInterface  removeAllObjects];
                [weakSelf.mutArraySecondaryInterface addObjectsFromArray:mg.mutMgArray];
            }else{
                [weakSelf.mutArraySecondaryInterface addObjectsFromArray:mg.mutMgArray];
            }
            [weakSelf.tableViewKnowledgeParty reloadData];
        }else{
            //            if ([str isEqualToString:@"重复登录"]&&page==0) {
            //                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZKnowledgeOfThePartyVC"];
            //            }else{
            //                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:str];
            //            }
            [LSZPublicClassDataToll initWithAlertKuangView:self.view string:str];
        }
    }];
    */
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZKnowledgeOfThePartyVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weakSelf = self;
    [self addNotificationCenter];
    weakSelf.mutArraySecondaryInterface = [[NSMutableArray alloc]init];
    [weakSelf.tableViewKnowledgeParty registerClass:[LSZDocumentdetailsCell class] forCellReuseIdentifier:@"LSZDocumentdetailsCell"];
    [weakSelf.tableViewKnowledgeParty registerClass:[LSZArticleHeaderTableViewCell class] forCellReuseIdentifier:@"LSZArticleHeaderTableViewCell"];
    //    [weakSelf.tableViewKnowledgeParty registerClass:[LSZHeadViewCell class] forHeaderFooterViewReuseIdentifier:@"LSZHeadViewCell"];
    self.page = 0;
    [weakSelf getInformationDetails:self.page ];
    [weakSelf.tableViewKnowledgeParty addRefreshHeaderWithHandle:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 刷新表格  和结束刷新
            self.page = 0;
            [weakSelf getInformationDetails:self.page ];
            [weakSelf.tableViewKnowledgeParty.mj_header endRefreshing];
        });
    }];
    weakSelf.tableViewKnowledgeParty.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //延时
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.page ++;
            [self getInformationDetails:self.page];
            [self.tableViewKnowledgeParty.mj_footer endRefreshing];
        });
    }];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //    return 200;
    return 0.00001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArraySecondaryInterface.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 200;
    }
    return 100;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UITableViewHeaderFooterView * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerCell"];
    if (!cell) {
        cell = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"headerCell"];
    }
    
    return cell;
    //    LSZHeadViewCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZHeadViewCell"];
    //    if (self.mutArraySecondaryInterface.count >0) {
    //        LSZArticleDetailsMg * mg = nil;
    //        mg = self.mutArraySecondaryInterface[0];
    //        [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:mg.coverUrl] placeholderImage:[UIImage imageNamed:@"默认"]];
    //    }
    //    return cell;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        LSZArticleHeaderTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZArticleHeaderTableViewCell" forIndexPath:indexPath];
        if (self.mutArraySecondaryInterface.count > indexPath.row) {
//            LSZArticleDetailsMg * mg = nil;
//            mg = self.mutArraySecondaryInterface[indexPath.row];
//            //            cell.articleDetailsMg = mg;
//            [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:mg.coverUrl] placeholderImage:[UIImage imageNamed:@"默认"]];
//            cell.labelTitle.text = mg.name;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        LSZDocumentdetailsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZDocumentdetailsCell" forIndexPath:indexPath];
        if (self.mutArraySecondaryInterface.count > indexPath.row) {
//            LSZArticleDetailsMg * mg = nil;
//            mg = self.mutArraySecondaryInterface[indexPath.row];
//            cell.articleDetailsMg = mg;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    

}
-(UITableView *)tableViewKnowledgeParty
{
    if (_tableViewKnowledgeParty == nil) {
        _tableViewKnowledgeParty = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height-44) style:UITableViewStyleGrouped];
        _tableViewKnowledgeParty.delegate = self;
        _tableViewKnowledgeParty.dataSource = self;
        _tableViewKnowledgeParty.estimatedRowHeight=0;
        _tableViewKnowledgeParty.estimatedSectionFooterHeight =0;
        _tableViewKnowledgeParty.estimatedSectionHeaderHeight =0;
        [_tableViewKnowledgeParty setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewKnowledgeParty
         ];
    }
    return _tableViewKnowledgeParty;
}
 
@end
